﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Rose.Models;
using System.Web.Security;


namespace Rose.Helper
{
    public class UserInfoHelpModel
    {
        private  Database_RoseEntities db = new Database_RoseEntities();

        public  int AddScore(string selfId, int addScore)
        {

            try
            {
                UserInfo selfInfo = db.UserInfos.Where(c=>c.Id==selfId).FirstOrDefault();
                if(selfInfo==null)
                    throw new ArgumentNullException();
                int currentScore = (selfInfo.Score += addScore);
                db.SaveChanges();
                return currentScore;
            }
            catch
            {
                return -1;
            }

        }

        public  int AddHit(string selfId)
        {
            try
            {
                 UserInfo selfInfo = db.UserInfos.Where(c=>c.Id==selfId).FirstOrDefault();
                if(selfInfo==null)
                    throw new ArgumentNullException();
                int currentHit = (selfInfo.Hit += 1);
                db.SaveChanges();
                return currentHit;
            }
            catch
            {
                return -1;
            }
        }

        public  int AddBeFocusCount(string beFocusUserId)
        {
            try
            {
                  UserInfo beFocusUserInfo = db.UserInfos.Where(c=>c.Id==beFocusUserId).FirstOrDefault();
                if(beFocusUserInfo==null)
                    throw new ArgumentNullException();
                int currentBeFocusUserCount = (beFocusUserInfo.BeFocusCount += 1);
                db.SaveChanges();
                return currentBeFocusUserCount;
            }
            catch
            {
                return -1;
            }
        }

        public  int AddFocusCount(string selfId)
        {
            try
            {
                 UserInfo selfInfo = db.UserInfos.Where(c=>c.Id==selfId).FirstOrDefault();
                if(selfInfo==null)
                    throw new ArgumentNullException();
                int currentFocusCount = (selfInfo.FocusCount += 1);
                db.SaveChanges();
                return currentFocusCount;
            }
            catch
            {
                return -1;
            }
        }

       
        //还没有完成的部分
        public  string GetHobbies(string selfId)
        {
            return string.Empty;
        }
        //还没有角色变化

        public  bool IsLoverExist(string selfId)
        {
            UserInfo selfInfo =new CheckHelpModel().CheckUserInfo(selfId);
            return selfInfo.HasLover;
        }

        public  void AddUserToLover(string selfId)
        {
            if(!Roles.IsUserInRole(selfId,"Lover"))
                Roles.AddUserToRole(selfId, "Lover");
            return;
        }

        public  void RemoveUserFromLover(string selfId)
        {
            if (Roles.IsUserInRole(selfId, "Lover"))
                Roles.RemoveUserFromRole(selfId, "Lover");
            return;
               
        }

        

        

    }
}